<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">.die()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/events/">事件</a> &gt; <a href="/category/events/event-handler-attachment/">绑定事件处理器</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/deprecated/">弃用</a> &gt; <a href="/category/deprecated/deprecated-1.7/">1.7 版本弃用的 API</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/removed/">已删除的函数</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/die/" target="_blank">.die()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="die1"><h2 class="section-title">
<span class="name">.die()</span><span class="returns">返回: <a href="/Types/#jQuery">jQuery</a></span><span class="version-details">version deprecated: <a href="/category/version/1.7/">1.7</a>, removed: <a href="/category/version/1.9/">1.9</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>
			  从元素中删除先前用<code>.live()</code>绑定的所有事件。</p>
<ul class="signatures">
<li class="signature" id="die">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.4.1/">1.4.1</a></span>.die()</h4>
<ul><li><div class="null-signature">这个方法不接受任何参数。</div></li></ul>
</li>
<li class="signature" id="die-eventType-handler">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.3/">1.3</a></span>.die( eventType [, handler ] )</h4>
<ul>
<li>
<div><strong>eventType</strong></div>
<div>类型: <a href="/Types/#String">String</a>
</div>
<div>
			一个包含一个JavaScript事件类型的字符串，比如<code>click</code> 或<code>keydown</code>。</div>
</li>
<li>
<div><strong>handler</strong></div>
<div>类型: <a href="/Types/#String">String</a>
</div>
<div>将来不再执行的函数。</div>
</li>
</ul>
</li>
<li class="signature" id="die-events">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.4.3/">1.4.3</a></span>.die( events )</h4>
<ul><li>
<div><strong>events</strong></div>
<div>类型: <a href="/Types/#PlainObject">PlainObject</a>
</div>
<div>
			包含一个或多个事件类型的一个普通对象，比如 <code>click</code> 或者 <code>keydown</code>并且其相应的函数将来不再被执行。
			</div>
</li></ul>
</li>
</ul>
<div class="longdesc" id="entry-longdesc">
<p>任何通过<code>.live()</code>绑定的处理程序都可以使用<code>.die()</code>删除。这个方法类似于调用不带参数的<code>.unbind()</code>，这是用来删除先前用<code>.bind()</code> 绑定的所有事件。见<code>.live()</code>和<code>.unbind()</code>讨论的更多详情。</p>
<p>如果不带参数使用，<code>.die()</code>将从元素中删除先前用<code>.live()</code>绑定的所有事件。</p>
<p><strong>从jQuery 1.7开始</strong>, <code>.die()</code>（
			和互补的方法<code>.live()</code>
			）是不建议使用的。
			 相反，推荐使用<a href="/off"><code>.off()</code></a>移除通过<a href="/on"><code>.on()</code></a>绑定的事件处理程序。</p>
<p><strong>注意:</strong> 为了.die()能正常工作，选择器使用它必须完全匹配选择器最初使用.live()。</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4>Example: <span class="desc">解除所有段落上绑定的 live 事件：</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">"p"</span>).die()</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-1">
<h4>Example: <span class="desc">解除所有段落上通过 live 事件绑定的 click 事件：</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>$(<span class="string">"p"</span>).die( <span class="string">"click"</span> )</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-2">
<h4>Example: <span class="desc">解除之前绑定的事件处理，将该事件处理作为第二个参数：</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="keyword">var</span> foo = <span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span></code></div></div><div class="container"><div class="line"><code>  <span class="comment">// code to handle some kind of event</span></code></div></div><div class="container"><div class="line"><code>};</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>$(<span class="string">"p"</span>).live(<span class="string">"click"</span>, foo); <span class="comment">// ... now foo will be called when paragraphs are clicked ...</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>$(<span class="string">"p"</span>).die(<span class="string">"click"</span>, foo); <span class="comment">// ... foo will no longer be called.</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article> </div>
</article>